package com.ywj.ehcache;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.search.Direction;
import net.sf.ehcache.search.Query;
import net.sf.ehcache.search.Result;
import net.sf.ehcache.search.attribute.AttributeType;
import net.sf.ehcache.search.expression.Criteria;

/**
 * EhCache缓存管理器
 * @author ywj.you
 * @version 2018-6-29
 * @descripttion
 */
public class EhcacheManager {

	private static CacheManager cacheManager = new CacheManager();

	private EhcacheManager(){

	}

	/**
	 * 获取EhCache缓存管理者
	 * @return
	 */
	public static CacheManager getCacheManager() {
		return cacheManager;
	}

	/**
	 * 获取Cache
	 * @param cacheName
	 * @return
	 */
	public static Cache getCache(String cacheName){
		return cacheManager.getCache(cacheName);
	}

	/**
	 * 无检索条件
	 * @param cql selec * from table
	 * @return
	 */
	public static List<Map<String, Object>> search(String cql){
		if(cql == null || "".equals(cql.trim())){
			return null;
		}
		Map<String, List<String>> condition = EhcacheManager.getSelectCondition(cql);
		return search(condition, null);
	}

	/**
	 * 获取缓存数据
	 * @param cql 使用“?”占位符方式替代的cql语句 selec * from table where id=? 
	 * @param paras {数据属性类型，运算值}
	 * @return
	 */
	public static List<Map<String, Object>> search(String cql,Object[][] paras){
		if(cql == null || "".equals(cql.trim())){
			return null;
		}
		Map<String, List<String>> condition = EhcacheManager.getSelectCondition(cql);
		List<String> operaValues = condition.get("operaValues");//操作运算值
		List<AttributeType> types = new ArrayList<AttributeType>();
		if(paras != null && paras.length > 0 && operaValues.size() == paras.length){
			for(int i = 0; i < operaValues.size(); i++){
				operaValues.set(i,String.valueOf(paras[i][1]));
				types.add((AttributeType) paras[i][0]);
			}
			condition.put("operaValues", operaValues);
		}
		return search(condition, types);
	}

	/**
	 * 获取缓存数据
	 * @param cql 类SQL语言的语句 selec * from table where id=123
	 * @param types 检索条件的常用数据类型 String、int、date等
	 * @return
	 */
	public static List<Map<String, Object>> search(String cql,List<AttributeType> types){
		if(cql == null || "".equals(cql.trim())){
			return null;
		}
		Map<String, List<String>> condition = EhcacheManager.getSelectCondition(cql);
		return search(condition, types);
	}

	@SuppressWarnings("unchecked")
	private static List<Map<String, Object>> search(Map<String, List<String>> condition,List<AttributeType> types){
		List<String> colums = condition.get("colums");//显示参数字段，默认*所有
		List<String> names = condition.get("names");//缓存实例名称
		List<String> operaKeys = condition.get("operaKeys");//操作关键字
		List<String> operaSigns = condition.get("operaSigns");//操作运算符
		List<String> operaValues = condition.get("operaValues");//操作运算值
		List<String> operaUnions = condition.get("operaUnions");//逻辑运算关系
		List<String> colbys = condition.get("colbys");//被排序参数
		List<String> orders = condition.get("orders");//排序
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		try{
			String cacheName = names.get(0);
			CacheManager cacheManager = EhcacheManager.getCacheManager();
			Cache cache = cacheManager.getCache(cacheName);
			Query query = cache.createQuery().includeKeys().includeValues();

			Criteria criteria = null;

			for(int i = 0; i < operaKeys.size(); i++){
				String operaKey = operaKeys.get(i);
				String operaSign = operaSigns.get(i);
				String operaValue = operaValues.get(i);
				String operaUnion = operaUnions.get(i);
				if("<".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).lt(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).lt(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).lt(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if("<=".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).le(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).le(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).le(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if(">".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).gt(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).gt(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).gt(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if(">=".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).ge(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).ge(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).ge(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if("!=".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).ne(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).ne(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).ne(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if("=".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).eq(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).eq(EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).eq(EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if("in".equals(operaSign)){
					Collection<Object> values = new ArrayList<Object>();
					String[] objs = operaValue.split(",");
					for(String obj : objs){
						values.add(EhcacheManager.getColumType(types.get(i),obj));
					}
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).in(values));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).in(values));
					}else{
						criteria = cache.getSearchAttribute(operaKey).in(values);
					}
				}else if("like".equals(operaSign)){
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).ilike((String) EhcacheManager.getColumType(types.get(i),operaValue)));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).ilike((String) EhcacheManager.getColumType(types.get(i),operaValue)));
					}else{
						criteria = cache.getSearchAttribute(operaKey).ilike((String) EhcacheManager.getColumType(types.get(i),operaValue));
					}
				}else if("between".equals(operaSign)){
					String[] objs = operaValue.split(",");
					if("and".equals(operaUnion)){
						criteria = criteria.and(cache.getSearchAttribute(operaKey).between(EhcacheManager.getColumType(types.get(i),objs[0]), EhcacheManager.getColumType(types.get(i),objs[1])));
					}else if("or".equals(operaUnion)){
						criteria = criteria.or(cache.getSearchAttribute(operaKey).between(EhcacheManager.getColumType(types.get(i),objs[0]), EhcacheManager.getColumType(types.get(i),objs[1])));
					}else{
						criteria = cache.getSearchAttribute(operaKey).between(EhcacheManager.getColumType(types.get(i),objs[0]), EhcacheManager.getColumType(types.get(i),objs[1]));
					}
				}
			}

			if(criteria != null){
				query = query.addCriteria(criteria);
			}

			//排序
			for(int i = 0; i < orders.size(); i++){
				query = "desc".equals(orders.get(i))
						? query.addOrderBy(cache.getSearchAttribute(colbys.get(i)), Direction.DESCENDING)
								: query.addOrderBy(cache.getSearchAttribute(colbys.get(i)), Direction.ASCENDING);
			}

			List<Result> datas = query.execute().all();

			for(int i = 0; i < datas.size(); i++){
				Map<String, Object> temp = new HashMap<String, Object>();
				Map<String, Object> map = (Map<String, Object>) datas.get(i).getValue();
				if(colums.contains("*")){
					list.add(map);
				}else{
					for(Object colum : colums){
						temp.put(colum.toString(), map.get(colum));
					}
					list.add(temp);
				}
			}

		}catch (Exception e) {
			e.printStackTrace();
		}

		return list;
	}

	/**
	 * 解析cql语句
	 * @param cql
	 * @return
	 */
	private static Map<String, List<String>> getSelectCondition(String cql){
		List<String> colums = new ArrayList<String>();
		List<String> names = new ArrayList<String>();
		List<String> operaKeys = new ArrayList<String>();
		List<String> operaSigns = new ArrayList<String>();
		List<String> operaValues = new ArrayList<String>();
		List<String> operaUnions = new ArrayList<String>();
		List<String> orders = new ArrayList<String>();
		List<String> colbys = new ArrayList<String>();
		Map<String, List<String>> condition = new HashMap<String, List<String>>();

		initCondition(cql, colums, names, operaKeys, operaSigns, operaValues, operaUnions);
		initOrder(cql, colbys, orders);

		condition.put("colums", colums);
		condition.put("names", names);
		condition.put("operaKeys", operaKeys);
		condition.put("operaSigns", operaSigns);
		condition.put("operaValues", operaValues);
		condition.put("operaUnions", operaUnions);
		condition.put("colbys", colbys);
		condition.put("orders", orders);
		return condition;
	}

	/**
	 * 解析cql初始化各种逻辑运算条件
	 * @param cql 类似于sql语句 select * from table
	 * @param colums 类似于数据库的字段[*]
	 * @param names 类似于数据库的表[table]
	 * @param operaKeys 操作的字段
	 * @param operaSigns 操作的运算符（<、<=、>、>=、!=、=、in、like、between）
	 * @param operaValues 操作的运算值
	 * @param operaUnions 操作的运算关系（空、and、or）
	 */
	private static void initCondition(String cql,List<String> colums,List<String> names,List<String> operaKeys,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		StringTokenizer tokens = new StringTokenizer(cql, "()+*/-=<>'`\"[]!, \n\r\f\t", true);
		String lastToken = new String();
		String nextToken = new String();
		operaUnions.add("");
		while (tokens.hasMoreTokens()) {
			nextToken = tokens.nextToken();
			if("select".equals(nextToken.toLowerCase())){
				initColums(tokens, colums);
				initNames(tokens, names);
			}

			if(!" ".equals(nextToken)){
				if("<".equals(nextToken)){
					operaKeys.add(lastToken);
					initLteCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if(">".equals(nextToken)){
					operaKeys.add(lastToken);
					initGteCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if("!".equals(nextToken)){
					operaKeys.add(lastToken);
					initNeqCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if("=".equals(nextToken)){
					operaKeys.add(lastToken);
					initEqCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if("in".equals(nextToken)){
					operaKeys.add(lastToken);
					initInCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if("like".equals(nextToken)){
					operaKeys.add(lastToken);
					initLikeCondition(tokens, operaSigns, operaValues, operaUnions);
				}else if("between".equals(nextToken)){
					operaKeys.add(lastToken);
					initBetweenCondition(tokens, operaSigns, operaValues, operaUnions);
				}
				lastToken = nextToken;
			}
		}
	}
	/**
	 * 解析cql初始化排序条件
	 * @param cql 类似于sql语句 select * from table
	 * @param colbys 排序字段
	 * @param orders 排序条件（asc、desc）
	 */
	private static void initOrder(String cql,List<String> colbys,List<String> orders){
		StringTokenizer tokens = new StringTokenizer(cql, "()+*/-=<>'`\"[]!, \n\r\f\t", true);
		String nextToken = new String();
		while (tokens.hasMoreTokens()) {
			nextToken = tokens.nextToken();
			if("order".equals(nextToken.toLowerCase())){
				String t = null;
				if(tokens.hasMoreTokens()){
					do{
						t = tokens.nextToken();
						if(!"order".equals(t.toLowerCase()) && !"by".equals(t.toLowerCase()) && !"desc".equals(t.toLowerCase()) && !"asc".equals(t.toLowerCase()) && !" ".equals(t) && !",".equals(t)){
							colbys.add(t);
						}else if("desc".equals(t.toLowerCase()) || "asc".equals(t.toLowerCase())){
							orders.add(t);
						}
					} while (tokens.hasMoreTokens());
				}
			}
		}
	}

	/**
	 * 初始化选择的参数（对应数据库：字段）
	 * @param tokens
	 * @param colums
	 */
	private static void initColums(StringTokenizer tokens,List<String> colums){
		String t = null;
		boolean e = false;
		do{
			t = tokens.nextToken();
			if(!"select".equals(t.toLowerCase()) && !"from".equals(t.toLowerCase()) && !" ".equals(t) && !",".equals(t)){
				if("*".equals(t.toLowerCase())){
					e = true;
				}else{
					colums.add(t);
				}
			}
		} while (!"from".equals(t) && tokens.hasMoreTokens());

		if(e){
			colums.clear();
			colums.add("*");
		}
	}
	/**
	 * 初始化选择的对象（对应数据库：表）
	 * @param tokens
	 * @param names
	 */
	private static void initNames(StringTokenizer tokens,List<String> names){
		String t = null;
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}
		names.add(t);
	}
	/**
	 * 初始化小于等于逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initLteCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		boolean e = false;
		t = tokens.nextToken();
		if("=".equals(t)){
			e = true;
		}
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}
		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x = t;
		}

		operaSigns.add(e ? "<=" : "<");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && !"order".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化大于等于逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initGteCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		boolean e = false;

		t = tokens.nextToken();
		if("=".equals(t)){
			e = true;
		}
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x = t;
		}
		operaSigns.add(e ? ">=" : ">");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化不等于逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initNeqCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t;
		String x = "";
		t = tokens.nextToken();//=
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x = t;
		}
		operaSigns.add("!=");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化等于逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initEqCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x = t;
		}
		operaSigns.add("=");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化包含逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initInCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("(".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!")".equals(t) && tokens.hasMoreTokens());
			}
		}
		operaSigns.add("in");
		x = x.substring(1,x.length()-1);
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化类似逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initLikeCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x = t;
		}

		operaSigns.add("like");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}
	/**
	 * 初始化范围逻辑运算条件
	 * @param tokens
	 * @param operaSigns
	 * @param operaValues
	 * @param operaUnions
	 */
	private static void initBetweenCondition(StringTokenizer tokens,List<String> operaSigns,List<String> operaValues,List<String> operaUnions){
		String t = null;
		String x = "";
		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x += t;
		}

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
				if(!" ".equals(t) && !"and".equals(t)){
					x += t;
				}
			}while(!"and".equals(t) && tokens.hasMoreTokens());
		}

		x += ",";

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(" ".equals(t) && tokens.hasMoreTokens());
		}

		if("'".equals(t)){
			x += t;
			if(tokens.hasMoreTokens()){
				do{
					t = tokens.nextToken();
					x += t;
				}while(!"'".equals(t) && tokens.hasMoreTokens());
			}
		}else{
			x += t;
		}
		operaSigns.add("between");
		operaValues.add(x.replace("'", ""));

		if(tokens.hasMoreTokens()){
			do{
				t = tokens.nextToken();
			}while(!"and".equals(t.toLowerCase()) && !"or".equals(t.toLowerCase()) && tokens.hasMoreTokens());
			if("and".equals(t.toLowerCase()) || "or".equals(t.toLowerCase())){
				operaUnions.add(t.toLowerCase());
			}
		}
	}

	/**
	 * 获取参数类型
	 * @param type
	 * @param value
	 * @return
	 */
	private static Object getColumType(AttributeType type,String value){
		if(AttributeType.STRING.equals(type)){
			return value;
		}
		if(AttributeType.INT.equals(type)){
			return Integer.parseInt(value);
		}
		if(AttributeType.LONG.equals(type)){
			return Long.parseLong(value);
		}
		if(AttributeType.DOUBLE.equals(type)){
			return Double.parseDouble(value);
		}
		if(AttributeType.FLOAT.equals(type)){
			return Float.parseFloat(value);
		}
		if(AttributeType.BOOLEAN.equals(type)){
			return Boolean.parseBoolean(value);
		}
		if(AttributeType.BYTE.equals(type)){
			return value.getBytes();
		}
		if(AttributeType.CHAR.equals(type)){
			return value.toCharArray();
		}
		if(AttributeType.DATE.equals(type)){
			try {
				return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value);
			} catch (ParseException e) {
				try {
					return new SimpleDateFormat("yyyy-MM-dd").parse(value);
				} catch (ParseException e1) {
					e1.printStackTrace();
				}
			}
		}
		return value;
	}
}
